package api.practice02;

import java.util.*;

public class CollectionDemo {
    public static void main(String[] args) {
        Collection<Pointer> c = new ArrayList<>();
        c.add(new Pointer(1, 2));
        c.add(new Pointer(2, 3));
        c.add(new Pointer(3, 4));
        c.add(new Pointer(4, 5));
        c.add(new Pointer(5, 6));
        System.out.println(c.size());//长度




        /*Integer i1 = new Integer(5);
        Integer i2 = new Integer(15);*/
        Collection<String> s = new ArrayList<>();
        s.add("1");
        s.add("2");
        // System.out.println(s);
        Collection<String> s1 = new ArrayList<>();
        s1.add("1");
        s1.add("2");
        // s.isEmpty();//判断集合是否为空集,返回bool类型
       /* System.out.println(s.isEmpty());
        Collection<String> s1 = new ArrayList<>();
        s1.add("i1");
        s1.add("i2");
        System.out.println(s1);
       // s1.clear();//清空集合
       // System.out.println(s1.isEmpty());
        boolean contains = s1.containsAll(s);
        System.out.println(contains);
        boolean b =  c.remove(new Pointer(1,2));
        System.out.println(c);*/
       /* s1.addAll(s);
        System.out.println(s1);
        s1.retainAll(s);
        System.out.println(s);//[1,2]是在s1的基础上操作的所有s的不变
        System.out.println(s1);
        s1.removeAll(s);
        System.out.println(s1);//空
        System.out.println(s);*/


        Collection<String> co = new ArrayList<>();
        co.add("one");
        co.add("#");
        co.add("two");
        co.add("#");
        co.add("three");
        co.add("#");
        co.add("four");
        co.add("#");
        co.add("five");
        System.out.println(co); //[one, #, two, #, three, #, four, #, five]
        Iterator<String> it = co.iterator();

        while (it.hasNext()) {
            String strings = it.next();
           // System.out.println(strings);
            if ("#".equals(strings)){
                it.remove();
            }
        }
        System.out.println(co);


        for (String str:co){
            System.out.println(str);
        }



        String[] string = co.toArray(new String[0]);//集合转换为数组
        System.out.println(Arrays.toString(string));


        String[] array = {"one", "two", "three", "four", "five"};
        List<String> list = Arrays.asList(array);//数组转换为集合
        System.out.println(list);


        array[1] = "2";
        System.out.println(Arrays.toString(array));
        System.out.println(list);


        list.set(3,"4");
        System.out.println(Arrays.toString(array));
        System.out.println(list);

    }
}
